<template>
  <div class="background">
    <div style="padding: 0 0 15px 15px;">
      <a-row>
        <a-col :span="5">
          <a-space>
            <a-button
              icon="left"
              @click.stop="goPrev"
            />
            <a-date-picker
              v-model:value="currentMonth"
              placeholder="选择日期"
              :allowClear="false"
              @change="onChangeDate"
            />
            <a-button
              icon="right"
              @click.stop="goNext"
            />
          </a-space>
        </a-col>
        <a-col :span="5">
          <a-row>
            <a-col :span="4"><span>车间：</span> </a-col>
            <a-col :span="10">
              <j-dict-select-tag
                v-model="queryParam.workshop"
                dictCode="workshop"
                style="width: 100px;"
                @change="searchQuery()"
              /></a-col>
          </a-row>
        </a-col>
        <a-col :span="5">
          <h3 style="margin:0;font-size:18px;font-weight: bold;">前纺计划产量</h3>
        </a-col>
        <a-col :span="8">
          <a-space style="float: right;">
            <a-button
              type="primary"
              @click="searchQuery()"
            >刷新</a-button>
            <a-button
              type="primary"
              icon="plus-circle"
              @click="handleAdd"
            >新增计划</a-button>
            <a-button
              icon="plus-circle"
              @click="copyYesterdayPlan"
            >复制昨日日计划</a-button>
            <a-button icon="plus-circle">导出日计划</a-button>
          </a-space>
        </a-col>
      </a-row>
    </div>
    <div
      class="XiSha"
      style="margin-top: 10px;padding:15px;"
    >
      <a-table
        ref="table"
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        @change="handleTableChange"
        bordered
        :scroll="{ x: true, y: true }"
      >
        <div
          slot="车间"
          slot-scope="text, record"
        >
          <j-dict-select-tag
            v-model="text"
            dictCode="workshop"
            style="width: 80px;"
            @change="selectChange(text, 'workshop', record)"
          />
        </div>
        <div
          slot="工序"
          slot-scope="text, record"
        >
          <div v-if="record.workingProcedure == '1'">
            <span>清花</span>
          </div>
          <div v-if="record.workingProcedure == '2'">
            <span>梳棉</span>
          </div>
          <div v-if="record.workingProcedure == '4'">
            <span>并条</span>
          </div>
          <div v-if="record.workingProcedure == '5'">
            <span>粗纱</span>
          </div>
        </div>
        <div
          slot="前纺品种"
          slot-scope="text, record"
        >
          <div v-if="record.workingProcedure == '1'">
            <j-dict-select-tag
              v-model="text"
              dictCode="crm_product_type_blowing,product_type,id"
              style="width: 150px;"
              @change="selectChange(text, 'productType', record)"
            />
          </div>
          <div v-if="record.workingProcedure == '2'">
            <j-dict-select-tag
              v-model="text"
              dictCode="crm_product_type_cotton,product_type,id"
              style="width: 150px;"
              @change="selectChange(text, 'productType', record)"
            />
          </div>
          <div v-if="record.workingProcedure == '4'">
            <j-dict-select-tag
              v-model="text"
              dictCode="crm_product_type_drawing,product_type,id"
              style="width: 150px;"
              @change="selectChange(text, 'productType', record)"
            />
          </div>
          <div v-if="record.workingProcedure == '5'">
            <j-dict-select-tag
              v-model="text"
              dictCode="crm_product_type_rove,product_type,id"
              style="width: 150px;"
              @change="selectChange(text, 'productType', record)"
            />
          </div>
        </div>
        <div
          slot="机号"
          slot-scope="text, record"
        >
          <a-space>
            <div v-html="getSeiresDevsnCs(record['preSpinDevices'])"></div>
            <a-button
              v-if="record.workingProcedure == '1'"
              type="primary"
              ghost
              size="small"
              icon="plus"
              @click="showModal(record, 'QingHua')"
            ></a-button>
            <a-button
              v-if="record.workingProcedure == '2'"
              type="primary"
              ghost
              size="small"
              icon="plus"
              @click="showModal(record, 'ShuMian')"
            ></a-button>
            <a-button
              v-if="record.workingProcedure == '4'"
              type="primary"
              ghost
              size="small"
              icon="plus"
              @click="showModal(record, 'BingTiao')"
            ></a-button>
            <a-button
              v-if="record.workingProcedure == '5'"
              type="primary"
              ghost
              size="small"
              icon="plus"
              @click="showModal(record, 'CuSha')"
            ></a-button>
          </a-space>
        </div>
        <!--        <div slot="甲A开台" slot-scope="text,record" style="display: flex;justify-content: center;">-->
        <!--          <a-space>-->
        <!--            <div v-html="getSeiresDevsnCs(record['adevices'])"></div>-->
        <!--            <a-button type="primary" ghost size="small" icon="plus" @click="showModal(record,'adevices')"></a-button>-->
        <!--          </a-space>-->
        <!--        </div>-->
        <!--        <div slot="乙B开台" slot-scope="text,record" style="display: flex;justify-content: center;">-->
        <!--          <a-space>-->
        <!--            <div v-html="getSeiresDevsnCs(record['bdevices'])"></div>-->
        <!--            <a-button type="primary" ghost size="small" icon="plus"-->
        <!--                      @click="showModal(record,'bdevices')"></a-button>-->
        <!--          </a-space>-->
        <!--        </div>-->
        <!--        <div slot="丙C开台" slot-scope="text,record" style="display: flex;justify-content: center;">-->
        <!--          <a-space>-->
        <!--            <div v-html="getSeiresDevsnCs(record['cdevices'])"></div>-->
        <!--            <a-button type="primary" ghost size="small" icon="plus"-->
        <!--                      @click="showModal(record,'cdevices')"></a-button>-->
        <!--          </a-space>-->
        <!--        </div>-->
        <!--        <div slot="锭数" slot-scope="text,record">-->
        <!--          <div v-if="record.workingProcedure == '1'">-->
        <!--            <span>{{ record.bproductTypeInfo.ingots }}</span>-->
        <!--          </div>-->
        <!--          <div v-if="record.workingProcedure == '2'">-->
        <!--            <span>{{ record.cproductTypeInfo.ingots }}</span>-->
        <!--          </div>-->
        <!--          <div v-if="record.workingProcedure == '4'">-->
        <!--            <span>{{ record.dproductTypeInfo.ingots }}</span>-->
        <!--          </div>-->
        <!--          <div v-if="record.workingProcedure == '5'">-->
        <!--            <span>{{ record.rproductTypeInfo.ingots }}</span>-->
        <!--          </div>-->
        <!--        </div>-->
        <!--        <div slot="定量" slot-scope="text,record">-->
        <!--          <div v-if="record.workingProcedure == '1'">-->
        <!--            <span>{{ record.bproductTypeInfo.ration }}</span>-->
        <!--          </div>-->
        <!--          <div v-if="record.workingProcedure == '2'">-->
        <!--            <span>{{ record.cproductTypeInfo.ration }}</span>-->
        <!--          </div>-->
        <!--          <div v-if="record.workingProcedure == '4'">-->
        <!--            <span>{{ record.dproductTypeInfo.ration }}</span>-->
        <!--          </div>-->
        <!--          <div v-if="record.workingProcedure == '5'">-->
        <!--            <span>{{ record.rproductTypeInfo.ration }}</span>-->
        <!--          </div>-->
        <!--        </div>-->
        <!--        <div slot="车速" slot-scope="text,record">-->
        <!--          <div v-if="record.workingProcedure == '1'">-->
        <!--            <span>{{ record.bproductTypeInfo.speed }}</span>-->
        <!--          </div>-->
        <!--          <div v-if="record.workingProcedure == '2'">-->
        <!--            <span>{{ record.cproductTypeInfo.speed }}</span>-->
        <!--          </div>-->
        <!--          <div v-if="record.workingProcedure == '4'">-->
        <!--            <span>{{ record.dproductTypeInfo.speed }}</span>-->
        <!--          </div>-->
        <!--          <div v-if="record.workingProcedure == '5'">-->
        <!--            <span>{{ record.rproductTypeInfo.speed }}</span>-->
        <!--          </div>-->
        <!--        </div>-->
        <div
          slot="车速对比"
          slot-scope="text, record"
        >
          <span v-if="text != null">{{ parseFloat(text) * 100 + '%' }}</span>
        </div>
        <div
          slot="品种批号"
          slot-scope="text, record"
        >
          <span>{{ text }}</span>
          <!-- <a-input
            v-model:value="record.productBatch"
            placeholder="请输入"
            @blur="selectChange(text, 'productBatch', record)"
            @focus="saveOldValue(text)"
          /> -->
        </div>
        <div
          slot="品种支别"
          slot-scope="text, record"
        >
          <span>{{ text }}</span>
          <!-- <a-input
            v-model:value="record.productBranch"
            placeholder="请输入"
            @blur="selectChange(text, 'productBranch', record)"
            @focus="saveOldValue(text)"
          /> -->
        </div>
        <div
          slot="设计参数车速"
          slot-scope="text, record"
        >
          <span>{{ text }}</span>
          <!-- <a-input
            v-model:value="record.designSpeed"
            placeholder="请输入"
            @blur="selectChange(text, 'designSpeed', record)"
            @focus="saveOldValue(text)"
          /> -->
        </div>
        <div
          slot="设计参数产量(台/12小时)"
          slot-scope="text, record"
        >
          <span>{{ text }}</span>
          <!-- <a-input
            v-model:value="record.designOutput"
            placeholder="请输入"
            @blur="selectChange(text, 'designOutput', record)"
            @focus="saveOldValue(text)"
          /> -->
        </div>
        <div
          slot="计划台数"
          slot-scope="text, record"
        >
          <span>{{ text }}</span>
          <!-- <a-input
            v-model:value="record.planOpen"
            placeholder="请输入"
            @blur="selectChange(text, 'planOpen', record)"
            @focus="saveOldValue(text)"
          /> -->
        </div>
        <div
          slot="计划停台"
          slot-scope="text, record"
        >
          <span>{{ text }}</span>
          <!-- <a-input
            v-model:value="record.unOpen"
            placeholder="请输入"
            @blur="selectChange(text, 'unOpen', record)"
            @focus="saveOldValue(text)"
          /> -->
        </div>
        <div
          slot="实际开台"
          slot-scope="text, record"
        >
          <span>{{ text }}</span>
          <!-- <a-input
            v-model:value="record.actualOpen"
            placeholder="请输入"
            @blur="selectChange(text, 'actualOpen', record)"
            @focus="saveOldValue(text)"
          /> -->
        </div>
        <div
          slot="开台产量"
          slot-scope="text, record"
        >
          <span>{{ parseFloat(text).toFixed(2) }}</span>
          <!-- <a-input
            v-model:value="record.output"
            placeholder="请输入"
            @blur="selectChange(text, 'output', record)"
            @focus="saveOldValue(text)"
          /> -->
        </div>
        <div
          slot="车速对比"
          slot-scope="text, record"
        >
          <span v-if="text != null">{{ (parseFloat(text) * 100).toFixed(2) + '%' }}</span>
          <!--          <a-input v-model:value="record.speedComparison" placeholder="请输入" @blur="selectChange(text,'speedComparison',record)"/>-->
        </div>
        <div
          slot="入库数量"
          slot-scope="text, record"
        >
          <span>{{ text }}</span>
          <!-- <a-input
            v-model:value="record.inQuantity"
            placeholder="请输入"
            @blur="selectChange(text, 'inQuantity', record)"
            @focus="saveOldValue(text)"
          /> -->
        </div>
        <div
          slot="开台数/12小时(A班)"
          slot-scope="text, record"
        >
          <span>{{ text }}</span>
          <!-- <a-input
            v-model:value="record.adeviceNum"
            placeholder="请输入"
            @blur="selectChange(text, 'adeviceNum', record)"
            @focus="saveOldValue(text)"
          /> -->
        </div>
        <div
          slot="开台数/12小时(B班)"
          slot-scope="text, record"
        >
          <span>{{ text }}</span>
          <!-- <a-input
            v-model:value="record.bdeviceNum"
            placeholder="请输入"
            @blur="selectChange(text, 'bdeviceNum', record)"
            @focus="saveOldValue(text)"
          /> -->
        </div>
        <!-- <div slot="开台数/8小时(C班)" slot-scope="text, record">
          <a-input
            v-model:value="record.cdeviceNum"
            placeholder="请输入"
            @blur="selectChange(text, 'cdeviceNum', record)"
            @focus="saveOldValue(text)"
          />
        </div> -->
        <div
          slot="开台产量/12小时(A班)"
          slot-scope="text, record"
        >
          <span>{{ parseFloat(text).toFixed(2) }}</span>
          <!-- <a-input
            v-model:value="record.aoutput"
            placeholder="请输入"
            @blur="selectChange(text, 'aoutput', record)"
            @focus="saveOldValue(text)"
          /> -->
        </div>
        <div
          slot="开台产量/12小时(B班)"
          slot-scope="text, record"
        >
          <span>{{ parseFloat(text).toFixed(2) }}</span>
          <!-- <a-input
            v-model:value="record.boutput"
            placeholder="请输入"
            @blur="selectChange(text, 'boutput', record)"
            @focus="saveOldValue(text)"
          /> -->
        </div>
        <!-- <div slot="开台产量/8小时(C班)" slot-scope="text, record">
          <a-input
            v-model:value="record.coutput"
            placeholder="请输入"
            @blur="selectChange(text, 'coutput', record)"
            @focus="saveOldValue(text)"
          />
        </div> -->
        <div
          slot="扣除损耗后产量"
          slot-scope="text, record"
        >
          <span>{{ parseFloat(text).toFixed(2) }}</span>
          <!-- <a-input
            v-model:value="record.deductLossOutput"
            placeholder="请输入"
            @blur="selectChange(text, 'deductLossOutput', record)"
            @focus="saveOldValue(text)"
          /> -->
        </div>
        <div
          slot="设计定额长度（百米/台/12小时）"
          slot-scope="text, record"
        >
          <span>{{ text }}</span>
          <!-- <a-input
            v-model:value="record.quotaLength"
            placeholder="请输入"
            @blur="selectChange(text, 'quotaLength', record)"
            @focus="saveOldValue(text)"
          /> -->
        </div>
        <div
          slot="品种代号"
          slot-scope="text, record"
        >
          <span>{{ text }}</span>
          <!-- <a-input
            v-model:value="record.productCode"
            placeholder="请输入"
            @blur="selectChange(text, 'productCode', record)"
            @focus="saveOldValue(text)"
          /> -->
        </div>
        <div
          slot="全称"
          slot-scope="text, record"
        >
          <span>{{ text }}</span>
          <!-- <a-input
            v-model:value="record.productTypeFullName"
            placeholder="请输入"
            @blur="selectChange(text, 'productTypeFullName', record)"
            @focus="saveOldValue(text)"
          /> -->
        </div>
        <div
          slot="锭数"
          slot-scope="text, record"
        >
          <span>{{ text }}</span>
          <!-- <a-input
            v-model:value="record.ingots"
            placeholder="请输入"
            @blur="selectChange(text, 'ingots', record)"
            @focus="saveOldValue(text)"
          /> -->
        </div>
        <div
          slot="定量"
          slot-scope="text, record"
        >
          <span>{{ text }}</span>
          <!-- <a-input
            v-model:value="record.ration"
            placeholder="请输入"
            @blur="selectChange(text, 'ration', record)"
            @focus="saveOldValue(text)"
          /> -->
        </div>
        <div
          slot="车速"
          slot-scope="text, record"
        >
          <span>{{ text }}</span>
          <!-- <a-input
            v-model:value="record.speed"
            placeholder="请输入"
            @blur="selectChange(text, 'speed', record)"
            @focus="saveOldValue(text)"
          /> -->
        </div>
        <div
          slot="效率"
          slot-scope="text, record"
        >
          <span v-if="text != null">{{ parseFloat(text) * 100 + '%' }}</span>
        </div>
        <div
          slot="产量（台/12小时）"
          slot-scope="text, record"
        >
          <span>{{ text }}</span>
          <!-- <a-input
            v-model:value="record.weight"
            placeholder="请输入"
            @blur="selectChange(text, 'weight', record)"
            @focus="saveOldValue(text)"
          /> -->
        </div>
        <div
          slot="长度（百米/台/12小时）"
          slot-scope="text, record"
        >
          <span>{{ text }}</span>
          <!-- <a-input
            v-model:value="record.length"
            placeholder="请输入"
            @blur="selectChange(text, 'length', record)"
            @focus="saveOldValue(text)"
          /> -->
        </div>
        <div
          slot="班用工数"
          slot-scope="text, record"
        >
          <span>{{ text }}</span>
          <!-- <a-input
            v-model:value="record.shiftWorkers"
            placeholder="请输入"
            @blur="selectChange(text, 'shiftWorkers', record)"
          /> -->
        </div>
        <div
          slot="粗纱管颜色"
          slot-scope="text, record"
        >
          <span>{{ text }}</span>
          <!-- <a-input
            v-model:value="record.tubeColor"
            placeholder="请输入"
            @blur="selectChange(text, 'tubeColor', record)"
            @focus="saveOldValue(text)"
          /> -->
        </div>
        <div
          slot="实际"
          slot-scope="text, record"
        >
          <span>{{ text }}</span>
          <!-- <a-input
            v-model:value="record.realWeight"
            placeholder="请输入"
            @blur="selectChange(text, 'realWeight', record)"
            @focus="saveOldValue(text)"
          /> -->
        </div>
        <div
          slot="调配"
          slot-scope="text, record"
        >
          <span>{{ text }}</span>
          <!-- <a-input
            v-model:value="record.fixWeight"
            placeholder="请输入"
            @blur="selectChange(text, 'fixWeight', record)"
            @focus="saveOldValue(text)"
          /> -->
        </div>
        <div
          slot="调后"
          slot-scope="text, record"
        >
          <span>{{ text }}</span>
          <!-- <a-input
            v-model:value="record.afterWeight"
            placeholder="请输入"
            @blur="selectChange(text, 'afterWeight', record)"
            @focus="saveOldValue(text)"
          /> -->
        </div>
        <div
          slot="损耗率%"
          slot-scope="text, record"
        >
          <span v-if="text != null">{{ parseFloat(text) * 100 + '%' }}</span>
          <!--          <a-input v-model:value="record.lossRate" placeholder="请输入" @blur="selectChange(text,'lossRate',record)"/>-->
        </div>
        <div
          slot="理论开台数"
          slot-scope="text, record"
        >
          <span>{{ text }}</span>
          <!-- <a-input
            v-model:value="record.theoreticalOpenings"
            placeholder="请输入"
            @blur="selectChange(text, 'theoreticalOpenings', record)"
            @focus="saveOldValue(text)"
          /> -->
        </div>
        <div
          slot="开台对比"
          slot-scope="text, record"
        >
          <span>{{ text }}</span>
          <!-- <a-input
            v-model:value="record.openingComparison"
            placeholder="请输入"
            @blur="selectChange(text, 'openingComparison', record)"
            @focus="saveOldValue(text)"
          /> -->
        </div>
        <div
          slot="action"
          slot-scope="text, record"
        >
          <a-popconfirm
            title="确认要移除吗?"
            ok-text="是"
            cancel-text="否"
            @confirm="handleDelete(record.id)"
          >
            <a href="#">移出</a>
          </a-popconfirm>
        </div>
      </a-table>
    </div>
    <cu-sha-modal
      ref="modalForm"
      @ok="modalFormOk"
      :planTime="queryParam.planTime"
    ></cu-sha-modal>
    <cu-sha-ji-tai-modal ref="jitaiModal"></cu-sha-ji-tai-modal>
  </div>
</template>

<script>
import moment from 'moment'
import CuShaModal from './modules/CuShaModal'
import CuShaJiTaiModal from './modules/CuShaJiTaiModal'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { copyYesterdayDailyPlan, editDailyPlanPreSpin } from '../../../api/customApi'

const path = '/crm_daily_plan_pre_spin/crmDailyPlanPreSpin'

const columns = [
  {
    title: '日期',
    dataIndex: 'planTime',
    align: 'center',
    key: 'planTime',
    width: 140,
    fixed: 'left'
  },
  {
    title: '车间',
    dataIndex: 'workshop',
    align: 'center',
    key: 'workshop',
    scopedSlots: { customRender: '车间' },
    width: 120,
    fixed: 'left'
  },
  // {
  //   title: '楼层',
  //   dataIndex: 'workshop',
  //   align: 'center',
  //   key: 'workshop',
  //   scopedSlots: { customRender: '楼层' },
  // },
  {
    title: '工序',
    dataIndex: 'workingProcedure',
    align: 'center',
    key: 'workingProcedure',
    scopedSlots: { customRender: '工序' },
    width: 100,
    fixed: 'left'
  },
  {
    title: '品种',
    children: [
      {
        title: '品名',
        align: 'center',
        width: 250,
        dataIndex: 'productType',
        key: 'productType',
        scopedSlots: { customRender: '前纺品种' }
      },
      {
        title: '批号',
        align: 'center',
        width: 200,
        dataIndex: 'productBatch',
        key: 'productBatch',
        scopedSlots: { customRender: '品种批号' }
      },
      {
        title: '支别',
        align: 'center',
        width: 100,
        dataIndex: 'productBranch',
        key: 'productBranch',
        scopedSlots: { customRender: '品种支别' }
      }
    ]
  },
  {
    title: '设计参数',
    children: [
      {
        title: '车速',
        align: 'center',
        width: 100,
        dataIndex: 'designSpeed',
        key: 'designSpeed',
        scopedSlots: { customRender: '设计参数车速' }
      },
      {
        title: '产量(台/12小时)',
        align: 'center',
        width: 200,
        dataIndex: 'designOutput',
        key: 'designOutput',
        scopedSlots: { customRender: '设计参数产量(台/12小时)' }
      }
    ]
  },
  {
    title: '日开台情况',
    children: [
      {
        title: '计划台数',
        align: 'center',
        width: 100,
        dataIndex: 'planOpen',
        key: 'planOpen',
        scopedSlots: { customRender: '计划台数' }
      },
      {
        title: '计划停台',
        align: 'center',
        width: 100,
        dataIndex: 'unOpen',
        key: 'unOpen',
        scopedSlots: { customRender: '计划停台' }
      },
      {
        title: '实际开台',
        align: 'center',
        width: 100,
        dataIndex: 'actualOpen',
        key: 'actualOpen',
        scopedSlots: { customRender: '实际开台' }
      },
      {
        title: '开台产量',
        align: 'center',
        width: 140,
        dataIndex: 'output',
        key: 'output',
        scopedSlots: { customRender: '开台产量' }
      },
      {
        title: '扣除损耗后产量',
        align: 'center',
        width: 150,
        dataIndex: 'deductLossOutput',
        key: 'deductLossOutput',
        scopedSlots: { customRender: '扣除损耗后产量' }
      },
      {
        title: '车速对比',
        align: 'center',
        width: 140,
        dataIndex: 'speedComparison',
        key: 'speedComparison',
        scopedSlots: { customRender: '车速对比' }
      }
    ]
  },
  {
    title: '开台数/班',
    children: [
      {
        title: '12小时(12班)',
        align: 'center',
        width: 200,
        dataIndex: 'adeviceNum',
        key: 'adeviceNum',
        scopedSlots: { customRender: '开台数/12小时(A班)' }
      },
      {
        title: '12小时(12班)',
        align: 'center',
        width: 200,
        dataIndex: 'bdeviceNum',
        key: 'bdeviceNum',
        scopedSlots: { customRender: '开台数/12小时(B班)' }
      }
      //   {
      //     title: '8小时(C班)',
      //     align: 'center',
      //     width: 200,
      //     dataIndex: 'cdeviceNum',
      //     key: 'cdeviceNum',
      //     scopedSlots: { customRender: '开台数/8小时(C班)' }
      //   }
    ]
  },
  {
    title: '开台产量/班',
    children: [
      {
        title: '12小时(A班)',
        align: 'center',
        width: 200,
        dataIndex: 'aoutput',
        key: 'aoutput',
        scopedSlots: { customRender: '开台产量/12小时(A班)' }
      },
      {
        title: '12小时(B班)',
        align: 'center',
        width: 200,
        dataIndex: 'boutput',
        key: 'boutput',
        scopedSlots: { customRender: '开台产量/12小时(B班)' }
      }
      // {
      //   title: '8小时(C班)',
      //   align: 'center',
      //   width: 200,
      //   dataIndex: 'coutput',
      //   key: 'coutput',
      //   scopedSlots: { customRender: '开台产量/8小时(C班)' }
      // }
    ]
  },
  {
    title: '设计定额长度（百米/台/12小时）',
    dataIndex: 'quotaLength',
    width: 250,
    align: 'center',
    key: 'quotaLength',
    scopedSlots: { customRender: '设计定额长度（百米/台/12小时）' }
  },
  {
    title: '机台号',
    width: 200,
    align: 'center',
    dataIndex: 'preSpinDevices',
    key: 'preSpinDevices',
    scopedSlots: { customRender: '机号' }
  },
  {
    title: '品种代号',
    dataIndex: 'productCode',
    width: 250,
    align: 'center',
    key: 'productCode',
    scopedSlots: { customRender: '品种代号' }
  },
  {
    title: '标准定额',
    children: [
      {
        title: '全称',
        dataIndex: 'productTypeFullName',
        width: 150,
        align: 'center',
        key: 'productTypeFullName',
        scopedSlots: { customRender: '全称' }
      },
      {
        title: '锭数',
        width: 100,
        align: 'center',
        key: 'ingots',
        dataIndex: 'ingots',
        scopedSlots: { customRender: '锭数' }
      },
      {
        title: '定量',
        align: 'center',
        width: 100,
        key: 'ration',
        dataIndex: 'ration',
        scopedSlots: { customRender: '定量' }
      },
      {
        title: '车速',
        align: 'center',
        width: 100,
        key: 'speed',
        dataIndex: 'speed',
        scopedSlots: { customRender: '车速' }
      },
      {
        title: '效率',
        align: 'center',
        width: 100,
        key: 'efficiency',
        dataIndex: 'efficiency',
        scopedSlots: { customRender: '效率' }
      },
      {
        title: '产量（台/12小时）',
        align: 'center',
        width: 200,
        key: 'weight',
        dataIndex: 'weight',
        scopedSlots: { customRender: '产量（台/12小时）' }
      },
      {
        title: '长度（百米/台/12小时）',
        width: 200,
        align: 'center',
        key: 'length',
        dataIndex: 'length',
        scopedSlots: { customRender: '长度（百米/台/12小时）' }
      },
      {
        title: '班用工数',
        align: 'center',
        width: 100,
        key: 'shiftWorkers',
        dataIndex: 'shiftWorkers',
        scopedSlots: { customRender: '班用工数' }
      },
      {
        title: '粗纱管颜色',
        align: 'center',
        width: 200,
        key: 'tubeColor',
        dataIndex: 'tubeColor',
        scopedSlots: { customRender: '粗纱管颜色' }
      }
    ]
  },
  {
    title: '前后工序产量',
    children: [
      {
        title: '实际',
        align: 'center',
        width: 100,
        dataIndex: 'realWeight',
        key: 'realWeight',
        scopedSlots: { customRender: '实际' }
      },
      {
        title: '调配',
        align: 'center',
        width: 100,
        dataIndex: 'fixWeight',
        key: 'fixWeight',
        scopedSlots: { customRender: '调配' }
      },
      {
        title: '调后',
        align: 'center',
        width: 100,
        dataIndex: 'afterWeight',
        key: 'afterWeight',
        scopedSlots: { customRender: '调后' }
      }
    ]
  },
  {
    title: '损耗率%',
    align: 'center',
    width: 100,
    dataIndex: 'lossRate',
    key: 'lossRate',
    scopedSlots: { customRender: '损耗率%' }
  },
  {
    title: '理论开台数',
    align: 'center',
    width: 100,
    dataIndex: 'theoreticalOpenings',
    key: 'theoreticalOpenings',
    scopedSlots: { customRender: '理论开台数' }
  },
  {
    title: '开台对比',
    align: 'center',
    width: 100,
    dataIndex: 'openingComparison',
    key: 'openingComparison',
    scopedSlots: { customRender: '开台对比' }
  },
  {
    title: '操作',
    align: 'center',
    width: 80,
    key: 'action',
    scopedSlots: { customRender: 'action' },
    fixed: 'right'
  }
]

export default {
  mixins: [JeecgListMixin],
  components: { CuShaModal, CuShaJiTaiModal },
  data () {
    return {
      currentMonth: moment(),
      title: '',
      ipagination: {
        current: 1,
        pageSize: 10,
        pageSizeOptions: ['10', '20', '30'],
        showTotal: (total, range) => {
          return range[0] + '-' + range[1] + ' 共' + total + '条'
        },
        showQuickJumper: true,
        showSizeChanger: true,
        total: 0
      },
      oldValue: '',
      isorter: {
        column: 'company,workshop,workingProcedure',
        order: 'asc,asc,asc'
      },
      queryParam: {
        planTime: moment().format('YYYY-MM-DD'),
        workshop: ''
      },
      columns,
      workHoursJa: 12,
      workHoursYb: 12,
      url: {
        list: path + '/list',
        delete: path + '/delete',
        deleteBatch: path + '/deleteBatch'
      }
    }
  },
  mounted () { },
  methods: {
    goPrev () {
      var newMonth = moment(this.currentMonth).subtract(1, 'day')
      this.currentMonth = newMonth
      this.queryParam.planTime = this.currentMonth.format('YYYY-MM-DD')
      this.searchQuery()
    },
    goNext () {
      var newMonth = moment(this.currentMonth).add(1, 'day')
      this.currentMonth = newMonth
      this.queryParam.planTime = this.currentMonth.format('YYYY-MM-DD')
      this.searchQuery()
    },
    onChangeDate (date, dateString) {
      this.queryParam.planTime = dateString
      this.searchQuery()
    },
    copyYesterdayPlan () {
      let query = {
        planTime: this.queryParam.planTime
      }
      copyYesterdayDailyPlan(query).then(res => {
        if (res.success) {
          this.$message.success('复制成功')
        }
        this.searchQuery()
      })
    },
    showModal (records, param) {
      this.$refs.jitaiModal.show(records, param, false)
    },
    // 获取联系机台-粗纱
    getSeiresDevsnCs (arr) {
      if (arr) {
        const resultArray = this.processData(arr)
        let str = ''
        if (resultArray) {
          resultArray.map(item => {
            let itemStr = `${item.jc}：${this.getSeiresDevsn(item.devSnArea)}`
            // let itemStr = `一纺：${this.getSeiresDevsn(item.devSnArea)}`
            str += itemStr
          })
        }
        return str
      }
    },
    processData (array) {
      const groupedByWorkshop = array.reduce((acc, curr) => {
        // const workshop = curr.workshop
        const workshop = curr.workshopDictText
        const deviceNo = curr.deviceNo

        // 检查 acc 中是否已经存在 workshop 对应的项，如果不存在则创建一个新的项
        if (!acc[workshop]) {
          acc[workshop] = {
            jc: workshop, // 这里的 jc 是你想要的字段名，存放 workshop 的值
            devSnArea: [deviceNo] // 创建一个新的数组存放 deviceNo
          }
        } else {
          // 如果已经存在，则将当前 deviceNo 添加到对应的 devSnArea 中
          acc[workshop].devSnArea.push(deviceNo)
        }

        return acc
      }, {})

      // 对每个 devSnArea 数组按照 deviceNo 的大小排序
      for (let workshop in groupedByWorkshop) {
        groupedByWorkshop[workshop].devSnArea.sort((a, b) => parseInt(a) - parseInt(b))
      }
      // 将结果转换为数组形式
      const resultArray = Object.values(groupedByWorkshop)

      return resultArray
    },
    // 获取连续车台
    getSeiresDevsn (arr) {
      var result = [],
        i = 0,
        str = []
      if (arr) {
        result[i] = [arr[0]]
        arr.reduce(function (prev, cur) {
          parseInt(cur) - parseInt(prev) === 1 ? result[i].push(cur) : (result[++i] = [cur])
          return cur
        })
        result.map(item => {
          if (item.length > 1) {
            str += `#${item[0]}~#${item[item.length - 1]}<br>`
          } else {
            str += `#${item[0]}<br>`
          }
        })
      } else {
        str = []
      }
      return str
    },
    saveOldValue (e) {
      this.oldValue = e
    },
    selectChange (value, label, record) {
      if (value == this.oldValue) {
        return
      }
      console.log(value)
      console.log(label)
      console.log(record)
      let query = {
        id: record.id,
        productBatch: record.productBatch,
        productBranch: record.productBranch,
        designOutput: record.designOutput,
        planOpen: record.planOpen,
        actualOpen: record.actualOpen,
        output: record.output,
        deductLossOutput: record.deductLossOutput,
        speedComparison: record.speedComparison,
        adeviceNum: record.adeviceNum,
        bdeviceNum: record.bdeviceNum,
        cdeviceNum: record.ddeviceNum,
        aoutput: record.aoutput,
        boutput: record.boutput,
        coutput: record.coutput,
        quotaLength: record.quotaLength,
        productCode: record.productCode,
        productTypeFullName: record.productTypeFullName,
        ingots: record.ingots,
        ration: record.ration,
        speed: record.speed,
        efficiency: record.efficiency,
        weight: record.weight,
        designSpeed: record.designSpeed,
        length: record.length,
        shiftWorkers: record.shiftWorkers,
        tubeColor: record.tubeColor,
        realWeight: record.realWeight,
        fixWeight: record.fixWeight,
        afterWeight: record.afterWeight,
        lossRate: record.lossRate,
        theoreticalOpenings: record.theoreticalOpenings,
        openingComparison: record.openingComparison,
        workshop: label == 'workshop' ? value : record.workshop,
        floor: label == 'floor' ? value : record.floor,
        productType: label == 'productType' ? value : record.productType,
        aproductType: label == 'productType' ? value : record.productType,
        bproductType: label == 'productType' ? value : record.productType,
        cproductType: label == 'productType' ? value : record.productType,
        company: record.company,
        adeviceIds: record.adeviceIds,
        bdeviceIds: record.bdeviceIds,
        cdeviceIds: record.cdeviceIds,
        unOpen: record.unOpen,
        temOutput: record.temOutput,
        aStartTime: record.aStartTime,
        aEndTime: record.aEndTime,
        bStartTime: record.bStartTime,
        bEndTime: record.bEndTime,
        cStartTime: record.cStartTime,
        cEndTime: record.cEndTime,
        planTime: record.planTime,
        workingProcedure: record.workingProcedure
      }
      editDailyPlanPreSpin(query).then(res => {
        if (res.success) {
          this.$message.success('修改成功')
        }
        this.loadData()
      })
    }
  }
}
</script>

<style lang="less" scoped>
.background {
  height: 100%;
  width: 100%;
  background-color: white;
  border-radius: 5px;
  box-shadow: 1px 4px 4px rgba(0, 0, 0, 0.05);
}

/* 去除Select组件的边框 */
/deep/ XiSha .ant-select-selection {
  display: block;
  box-sizing: border-box;
  background-color: #fafafa;
  border: 0;
  border-top-width: 1.02px;
  border-radius: 4px;
  outline: none;
  transition: all 0.3s cubic-bezier(0.645, 0.045, 0.355, 1);
  -webkit-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

/deep/ XiSha .ant-select-focused .ant-select-selection,
.ant-select-selection:focus,
.ant-select-selection:active {
  border-color: #fafafa;
  border-right-width: 1px !important;
  outline: 0;
  box-shadow: none;
}

.add-btn {
  width: 14px;
  height: 14px;
  padding: 0;
  text-align: center;
  line-height: 11px;
  border-radius: 2px;
  border: 1px solid #1790ff;
  color: #1790ff;
  font-size: 12px;
  cursor: pointer;
  margin-left: 4px;
}
</style>
